package lc;

import java.util.Arrays;

import org.junit.Test;

public class Ex34 {
    class Solution {
        public int[] searchRange(int[] nums, int target) {
            int hi = nums.length - 1, lo = 0, mid;
            while (lo < hi) {
                mid = (hi - lo) / 2 + lo;
                if (nums[mid] < target) {
                    lo = mid + 1;
                } else {
                    hi = mid;
                }
            }
            int start = lo;
            if (nums[start] != target) {
                start = -1;
            }
            lo = 0;
            hi = nums.length - 1;
            while (lo < hi) {
                mid = (hi - lo + 1) / 2 + lo;
                if (nums[mid] > target) {
                    hi = mid - 1;
                } else {
                    lo = mid;
                }
            }
            if (nums[lo] != target) {
                lo = -1;
            }
            return new int[]{start, lo};
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{5,7,7,8,8,10};
        System.out.println(Arrays.toString(s.searchRange(nums, 8)));
    }
}
